package module.building.view.buildingButtonsPanel
{
	import code.consts.FilterConst;
	import code.utils.ButtonUtil;
	import code.utils.TextFieldUtil;
	
	import com.darwin.darwinUI.containers.Box;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.controls.LabelButton;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.DarwinFont;
	import com.darwin.darwinUI.general.TextFieldFactory;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import module.building.event.BuildEvent;
	import module.main.view.ResourceConst;

	/**
	 * 建造状态下的操作按钮面板 
	 * @author hc
	 */
	public class BuildingButtonsPanel extends UIComponent
	{
		private var diyButtonContainer:UIComponent;
		private var optionButtonContainer:UIComponent;
		
		private const H_DISTANCE:int = 75;
		private const V_DISTANCE:int = 70;
		
		public function BuildingButtonsPanel()
		{
			super();
			init();
		}
		
		private var _buildButton:LabelButton;
		private var _moveButton:LabelButton;
		private var _removeButton:LabelButton;
		private var _regainButton:LabelButton;
		private var _confirmButton:LabelButton;
		private var _cancelButton:LabelButton;
		private function init():void
		{	
			optionButtonContainer = new UIComponent();
			optionButtonContainer.autoSize = true;
			diyButtonContainer = new UIComponent();
			diyButtonContainer.autoSize = true;
			diyButtonContainer.y = V_DISTANCE;
			addChild(optionButtonContainer)
			addChild(diyButtonContainer);
			
			_buildButton = ButtonUtil.getReformBtn(ResourceConst.REFORM_BUILD_ICON,new Label("建造"));		
			_moveButton = ButtonUtil.getReformBtn(ResourceConst.REFORM_MOVE_ICON,new Label("移动"));	
			_removeButton = ButtonUtil.getReformBtn(ResourceConst.REFORM_REMOVE_ICON,new Label("移除"));	
			_regainButton = ButtonUtil.getReformBtn(ResourceConst.REFORM_RECYCLING_ICON,new Label("回收"));			
			_confirmButton = ButtonUtil.getReformBtn(ResourceConst.REFORM_CONFIRM_ICON,new Label("确定"));		
			_cancelButton = ButtonUtil.getReformBtn(ResourceConst.REFORM_CANCEL_ICON,new Label("取消"));		
			
			optionButtonContainer.addChild(_cancelButton);
			optionButtonContainer.addChild(_confirmButton);
			
			diyButtonContainer.addChild(_buildButton);
			diyButtonContainer.addChild(_moveButton);
			diyButtonContainer.addChild(_removeButton);
			diyButtonContainer.addChild(_regainButton);
			
			for(var i:int=0;i<optionButtonContainer.numChildren;i++)
			{
				optionButtonContainer.getChildAt(i).x = (i+2)*H_DISTANCE;
				optionButtonContainer.getChildAt(i).addEventListener(MouseEvent.CLICK, buttonClickHandler);
				optionButtonContainer.getChildAt(i).addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
				optionButtonContainer.getChildAt(i).addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
			}
			
			for(i=0;i<diyButtonContainer.numChildren;i++)
			{
				diyButtonContainer.getChildAt(i).x = i*H_DISTANCE;
				diyButtonContainer.getChildAt(i).addEventListener(MouseEvent.CLICK, buttonClickHandler);
				diyButtonContainer.getChildAt(i).addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
				diyButtonContainer.getChildAt(i).addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
			}

			width = diyButtonContainer.numChildren*H_DISTANCE;
			height = this.numChildren*V_DISTANCE;
		}
		
		/**
		 * 当按钮面板上的一个按钮被点击时，抛出按钮选择事件，并包含相应数据 
		 */
		private function buttonClickHandler(e:MouseEvent):void
		{
			var type:String = "";
			switch(e.currentTarget){
				case _buildButton:
					type = "build";
					break;
				case _confirmButton:
					type = "confirm";
					break;
				case _cancelButton:
					type = "cancel";
					break;
				case _moveButton:
					type = "move";
					break;
				case _removeButton:
					type = "remove";
					break;
				case _regainButton:
					type = "regain";
					break;
				default:break;
			}
			var event:BuildEvent = new BuildEvent(BuildEvent.BUILD_BUTTON_SELECT,type);
			dispatchEvent(event);
		}
				
		private function rollOverHandler(e:MouseEvent):void
		{
			(e.target as LabelButton).filters = [FilterConst.WHIGHT_GLOW_FILTER];
		}
		
		private function rollOutHandler(e:MouseEvent):void
		{
			(e.target as LabelButton).filters = [];
		}
	}
}